Descrição do trabalho:
http://webserver2.tecgraf.puc-rio.br/~mgattass/visao/trb/T1.html
Aluno: Daniel da Silva Costa
E-mail: danieldasilvacosta@gmail.com
from google.colab import drive
drive.mount('/content/drive/')
cd "drive/MyDrive/Doutorado/Disciplinas/[2022.2] [PUC-Rio] Visão Computacional - Professor Marcelo Gattass/Trabalhos/Trabalho 1/"
!pwd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as pim
path = './imagens/fotos/'
img = pim.imread( path + 'fuji/25688225598_63d3e2ed15_o.jpg' )
img
# plt.figure( figsize=(6, 6) )
plt.figure( figsize=(10, 10) )
plt.title( 'Fuji Mountain' )
plt.imshow( img )
plt.show()
def describe_image( img ):
h, w, nc = img.shape
print( f'shape = {img.shape}' )
print( f'dtype = {img.dtype}' )
print( f'w = {w}' )
print( f'h = {h}' )
print( f'número de canais de cor = {nc}' )
print( f'min = { np.amin(img) }' )
print( f'max = { np.amax(img) }' )
describe_image( img )
imgf = img / 255.0
describe_image( imgf )
fig, axes = plt.subplots( 1, 2, figsize=(20, 10) )
axes[0].set_title( '[0, 255]' )
axes[0].imshow( img )
axes[1].set_title( '[0.0, 1.0]' )
axes[1].imshow( imgf )
plt.show()
cmap sem ser gray mapeia tons mais escuros para azul e mais claros para amarelo.
def lum( rgb ):
return np.dot( rgb, [0.2126, 0.7152, 0.0722] )
gray = lum( imgf )
print( gray.shape )
fig, axes = plt.subplots( 1, 3, figsize=( 30, 10 ) )
axes[0].set_title( 'Original' )
axes[0].imshow( img )
axes[1].set_title( 'Tons de Cinza' )
axes[1].imshow( gray, cmap='gray' )
axes[2].set_title( 'Sem ser em tons de cinza' )
axes[2].imshow( gray )
plt.show()
plt.figure( figsize=(10, 5) )
plt.title( 'Histograma' )
plt.hist( gray.ravel(), 255 )
plt.xlim( [0, 1] )
plt.show()
gray
square = np.square( gray )
square
x = [2, 3, 4]
np.square( x )
plt.figure( figsize=(10, 5) )
plt.title( 'Em cinza' )
plt.imshow( square, cmap='gray' )
plt.show()
sqrt = np.sqrt( gray )
sqrt
plt.figure( figsize=(10, 5) )
plt.title( 'Em cinza' )
plt.imshow( sqrt, cmap='gray' )
plt.show()
fig, axes = plt.subplots( 2, 2, figsize=( 20, 10 ) )
axes[0][0].set_title( 'Original Image' )
axes[0][0].imshow( img )
axes[0][1].set_title( 'Gray' )
axes[0][1].imshow( gray, cmap='gray' )
axes[1][0].set_title( 'Square' )
axes[1][0].imshow( square, cmap='gray' )
axes[1][1].set_title( 'SQRT' )
axes[1][1].imshow( sqrt, cmap='gray' )
plt.show()
w = img.shape[1]
x = np.linspace(0, w-1, w)
line_heights = [100, 300, 550, 800]
fig, axes = plt.subplots(
nrows=2, ncols=len( line_heights ),
figsize=( 50, 20 ),
squeeze=False )
for i, line_height in enumerate( line_heights ):
axes[0][i].set_title( 'Imagem' )
axes[0][i].imshow( img )
axes[1][i].set_title( f'Linha (line_height: {line_height})' )
axes[1][i].plot( x, img[ line_height, :, 0], color = 'red' )
axes[1][i].plot( x, img[ line_height, :, 1], color = 'green' )
axes[1][i].plot( x, img[ line_height, :, 2], color = 'blue' )
axes[1][i].set_xlim( [0, w-1] )
# Draw a line on the image
axes[0][i].plot(
[ 0, w-1 ],
[ line_height, line_height ],
color = 'yellow' )
plt.show()
%%time
!jupyter nbconvert --to html ./T1_DanielCosta_FOTOS.ipynb